package com.example.order;

import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import com.example.order.utils.IDWorker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: songyahui
 * @Date: 2020/11/6 18:30
 * @Version 1.0
 */
@SpringBootApplication
@EnableDubboConfiguration
public class PayApplication {
    public static void main(String[] args) {
        SpringApplication.run(PayApplication.class,args);
    }

//    common包中已经创建bean，该行过期，开启会报bean实例冲突
//    @Bean
//    public IDWorker getBean(){
//        1:数据id，2机器id
//        return new IDWorker(1,2);
//    }
    @Bean
    public ThreadPoolTaskExecutor getThreadPool(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(4);
        executor.setMaxPoolSize(8);
        executor.setQueueCapacity(100);
        executor.setKeepAliveSeconds(60);
        executor.setThreadNamePrefix("Pool-A");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
